﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        //在 Main 方法中创建一个字符串类型的数组，并存入 5 个值，然后将数组中下标是偶数的元素输出。
        static void Main(string[] args)
        {
            Text4();
        }
        public static void Text()
        {
            String[] arr = { "1", "2", "3", "4", "6" };
            for (int i = 0; i < arr.GetLength(0); i++)
            {
                Console.WriteLine("偶数有：" + arr[1] + arr[3] + arr[4] + "\t");
                break;
            }
            Console.WriteLine();

        }
        public static void Text1()
        {
            String arr = "adas ds  ad12 34";
            int Isdigincount = 0;
            int IsLettercount = 0;
            int IsWhiteSpacecount = 0;
            foreach (char c in arr)
            {
                if (char.IsDigit(c))
                {
                    Isdigincount++;
                }
                else if (char.IsLetter(c))
                {
                    IsLettercount++;
                }
                else if (char.IsWhiteSpace(c))
                {
                    IsWhiteSpacecount++;
                }
            }
            Console.WriteLine("字符串中，数字有{0}，字母有{1}，空格有{2}", Isdigincount, IsLettercount, IsWhiteSpacecount);

        }
////        在 Main 方法中创建一个 double 类型的数组，并在该数组中存入 5 名学生的考试成绩
//        (控制台输入)，计算总成绩和平均成绩。
////要求使用foreach语句实现该功能，
        public static void Text2()
        {
            double[] arr = new double[5];
            double sum = 0;
            double avg = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine("请输入成绩：");
                double a = double.Parse(Console.ReadLine());
                arr[i] = a;
            }
            foreach (double item in arr)
            {
                sum += item;
                avg = item / 5;
            }
            Console.WriteLine("他们的和为{0}，平均值为{1}",sum,avg );
        }
        public static void Text3() {
            int[] arr = { 20, 40, 50, 60, 70 };
            int temp = 0;
            for (int i = 0; i < arr.Length-1; i++)
            {
                for (int j = 0; j <arr.Length-i-1; j++)
                {
                    if (arr[j]<arr[j+1])
                    {
                        temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                }
            }
        
                Console.WriteLine("结果是：");
                foreach (int item in arr)
                {
                    Console.Write(item+ " ");
     
                }
                Console.WriteLine();
        }
//        实现查找数组元素索引的功能。
//定义一个数组，然后控制台输入要查找的元素，返回输入值在数组中最后一次出现的位置。若是找不到，请打印找不到。
        public static void Text4() {
            int[] a = { 98, 10, 20, 40, 30 };
            Console.WriteLine("请输入一个数");
            int b = int.Parse(Console.ReadLine());
            int index = -1;
            for (int i = 0; i < a.Length; i++)
            {
                if (b==a[i])
                {
                    index = i;
                }
            }
                if (index != -1)
                {
                    Console.WriteLine("{0}在数组中出现是{1}",b,index);
                }
                else
                {
                    Console.WriteLine("找不到");
                }
                Console.WriteLine();
        
        }

        static void Test5()
        {
            Console.WriteLine("乘法表");
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j < 10; j++)
                {
                    if (j <= i)
                    {
                        Console.Write(i + "*" + j + "=" + i * j + "\t");
                    }

                }
                Console.WriteLine();
            }
        }
        static void Test6()
        {
            Console.WriteLine("空心正方形");
            Console.WriteLine("请输入正方形的边长：");
            int a = int.Parse(Console.ReadLine());

            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < a; j++)
                {
                    if (i == 0 || j == 0 || j == a - 1 || i == a - 1)
                    {
                        Console.Write("*" + " ");
                    }
                    else
                    {
                        Console.Write(" " + " ");
                    }
                }
                Console.WriteLine();
            }
        }

        static void Test7()
        {
            Console.WriteLine("菱形");
            Console.WriteLine("请输入菱形的边长：");
            int n = int.Parse(Console.ReadLine());

            for (int i = 1; i <= n; i++)
            {
                for (int j = n - 1; j >= i; j--)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= i * 2 - 1; k++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            for (int i = n - 1; i >= 1; i--)
            {
                for (int j = i - 1; j < n - 1; j++)
                {
                    Console.Write(" ");
                }
                for (int l= 1; k <= i * 2 - 1; l++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
        }
    }
}
   
